package com.itany.shop.util;

import java.util.List;

/**
 * @Author:石小俊
 * @Date:2022/11/16 11:27
 * @Version:1.0-SNAPSHOT
 * @Description:
 */
public class PageInfo<T> {

    // 总数据记录数
    private int count;
    // 当前页的所有数据
    private List<T> list;
    // 当前页的页码
    private int pageNo;
    // 每页多少条数据
    private int pageSize;
    // 页码总数
    private int pages;

    public PageInfo(int count, List<T> list, int pageNo, int pageSize) {
        this.count = count;
        this.list = list;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        // 根据已知条件,获取到总页数
        pages = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    /**
     * 获取上一页
     * @return
     */
    public int getPrePage(){
        return pageNo > 1 ? pageNo - 1 : 1;
    }

    /**
     * 获取下一页
     * @return
     */
    public int getNextPage(){
        return pageNo < pages ? pageNo + 1 : pages;
    }

    /**
     * 获取首页
     * @return
     */
    public int getFirstPage(){
        return 1;
    }

    /**
     * 获取尾页
     * @return
     */
    public int getLastPage(){
        return pages;
    }

}
